package com.beiye.drivertransport.specifiedLearning.business;

import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.android.frame.adapter.CommonAdapter;
import com.android.frame.adapter.ViewHolder;
import com.android.frame.http.HttpListener;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.SubActivity.EnterpriseAdministratorCourseDetailsActivity;
import com.beiye.drivertransport.SubActivity.SpecifiedLearningCourseDetailsAgainActivity;
import com.beiye.drivertransport.activity.TwoBaseAty;
import com.beiye.drivertransport.bean.CourseDetailBean;
import com.beiye.drivertransport.bean.LoginUserBean;
import com.beiye.drivertransport.bean.SpecifiedLearningCourseBean;
import com.beiye.drivertransport.bean.SpecifiedPhotoBean;
import com.beiye.drivertransport.config.AppInterfaceConfig;
import com.beiye.drivertransport.http.Login;
import com.beiye.drivertransport.utils.CameraCanUseUtils;
import com.beiye.drivertransport.utils.TiShiDialog;
import com.beiye.drivertransport.utils.ToastUtil;
import com.beiye.drivertransport.utils.UserManger;
import com.beiye.drivertransport.utils.Utils;
import com.githang.statusbar.StatusBarCompat;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.squareup.picasso.Picasso;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;


import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

//企业管理员课程列表
 public class SpecifiedLearningBusinessActivity extends TwoBaseAty {

    ImageView img_safeback;

    ListView lv_course;

    View empty_view;

    TextView tv_title;
    private static final int REQUEST_EXTERNAL_STORAGE = 1;
    private static String[] PERMISSIONS_STORAGE = {
            "android.permission.READ_EXTERNAL_STORAGE",
            "android.permission.WRITE_EXTERNAL_STORAGE"};
    ArrayList<SpecifiedLearningCourseBean.RowsBean> courseList = new ArrayList<>();
    ArrayList<SpecifiedLearningCourseBean.RowsBean> courseList1 = new ArrayList<>();
    private SpecifiedLearningBusinesscourseAdapter specifiedLearningBusinesscourseAdapter;
    private int minPer;

    @Override
     public int getLayoutId() {
         return R.layout.activity_specified_learning_business;
    }

    public void onClick(View view) {
        if (view.getId() == R.id.img_safeback) {
            finish();
        }
    }
     @Override
     public void initData() {
         img_safeback = (ImageView) findViewById(R.id.img_safeback);
         lv_course = (ListView) findViewById(R.id.lv_course);
         empty_view = (View) findViewById(R.id.empty_view);
         tv_title = (TextView) findViewById(R.id.tv_title);
         StatusBarCompat.setStatusBarColor(this, Color.parseColor("#1F80C4"));
         initUi();
     }
    private void initUi() {

        lv_course.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {

                //检测是否有写的权限
                int permission = ActivityCompat.checkSelfPermission(SpecifiedLearningBusinessActivity.this,
                        "android.permission.WRITE_EXTERNAL_STORAGE");
                if (permission != PackageManager.PERMISSION_GRANTED) {
                    // 没有写的权限，去申请写的权限，会弹出对话框
                    ActivityCompat.requestPermissions(SpecifiedLearningBusinessActivity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
                    return;
                }
                if (!CameraCanUseUtils.isCameraCanUse()) {

                    ToastUtil.showShortToast(SpecifiedLearningBusinessActivity.this, "请到手机设置界面里找驾运宝允许开启照相");
                } else {
                    if (specifiedLearningBusinesscourseAdapter.getItem(position).getMark() == 0) {
                        showLoadingDialog("");
                        int tcSn = specifiedLearningBusinesscourseAdapter.getItem(position).getTcSn();
                        int readLength = specifiedLearningBusinesscourseAdapter.getItem(position).getReadLength();
                        int atcSn = specifiedLearningBusinesscourseAdapter.getItem(position).getAtcSn();
                        int sn = specifiedLearningBusinesscourseAdapter.getItem(position).getSn();
                        courseList1.clear();
                        for (int i = 0; i < courseList.size(); i++) {
                            if (courseList.get(i).getTcSn() != tcSn && courseList.get(i).getMark() != 1) {
                                courseList1.add(courseList.get(i));
                            }

                        }
                        SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                Context.MODE_PRIVATE);
                        int utchSn = sp.getInt("utchSn", 0);
                        int faceRecgMark = sp.getInt("faceRecgMark", 0);
                        int tphotoMark = sp.getInt("tphotoMark", 0);
                        String photoUrl = sp.getString("photoUrl", "");
                        Bundle bundle = new Bundle();
                        bundle.putInt("tcsn", tcSn);
                        bundle.putInt("atcSn", atcSn);
                        if(sn==0)
                        {
                            bundle.putInt("sn", 0);
                        }else{
                            bundle.putInt("sn", sn);
                        }
                        bundle.putInt("utchSn", utchSn);//学时序列号
                        bundle.putInt("readLength", readLength);//保存时间
                        bundle.putSerializable("CourseDetailList", (Serializable) courseList1);
                        bundle.putInt("tphotoMark", tphotoMark);
                        bundle.putInt("faceRecgMark", faceRecgMark);
                        bundle.putString("photoUrl",photoUrl);
                        bundle.putInt("minPer", minPer);
                        startActivity(EnterpriseAdministratorCourseDetailsActivity.class, bundle);

                    } else if (specifiedLearningBusinesscourseAdapter.getItem(position).getMark() == 1) {
                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SpecifiedLearningBusinessActivity.this);
                        builder1.setMessage("您已学习了该课程，继续浏览课程将不记录时间");
                        builder1.setTitle("提示:");
                        builder1.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                int tcSn = specifiedLearningBusinesscourseAdapter.getItem(position).getTcSn();
                                Bundle bundle = new Bundle();
                                bundle.putInt("tcsn", tcSn);
                                startActivity(SpecifiedLearningCourseDetailsAgainActivity.class, bundle);
                                //设置你的操作事项
                            }
                        });
                        builder1.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();

                            }
                        });
                        builder1.create().show();

                    }
                }

            }
        });
    }
     @Override
     public void requestData() {
         Bundle bundle = getIntent().getExtras();
         int tphotoMark = bundle.getInt("tphotoMark");
         minPer = bundle.getInt("minPer");
         int plansn = bundle.getInt("plansn");
         int faceRecgMark = bundle.getInt("faceRecgMark");
         int utchSn = bundle.getInt("utchSn");
         String photoUrl = bundle.getString("photoUrl");
         SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                 Context.MODE_PRIVATE);
         SharedPreferences.Editor edit = sp.edit();
         edit.putInt("utchSn",utchSn);
         edit.putInt("tphotoMark",tphotoMark);
         edit.putInt("faceRecgMark",faceRecgMark);
         edit.putString("photoUrl",photoUrl);
         edit.commit();
         showLoadingDialog("");
         new Login().getNewSpecifiedBusinesscourseitem(plansn,utchSn,this, 1);
     }
    @Override
    protected void onResume() {
        requestData();
        super.onResume();
    }
    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        if (what == 1) {
            dismissLoadingDialog();
            SpecifiedLearningCourseBean learnCourseBean = JSON.parseObject(result, SpecifiedLearningCourseBean.class);
            List<SpecifiedLearningCourseBean.RowsBean> rows = learnCourseBean.getRows();
            if (rows.size() == 0) {
                lv_course.setEmptyView(empty_view);
                return;
            }
            courseList.clear();
            courseList.addAll(rows);
            specifiedLearningBusinesscourseAdapter = new SpecifiedLearningBusinesscourseAdapter(SpecifiedLearningBusinessActivity.this, courseList, R.layout.specified_course_item);
            lv_course.setAdapter(specifiedLearningBusinesscourseAdapter);
        }
        super.onSuccess(result, call, response, what);
    }
    public class SpecifiedLearningBusinesscourseAdapter extends CommonAdapter<SpecifiedLearningCourseBean.RowsBean> {
        private Context context;
        private List<SpecifiedLearningCourseBean.RowsBean> mList;
        private PopupWindow mPopWindow;


        public SpecifiedLearningBusinesscourseAdapter(Context context, List<SpecifiedLearningCourseBean.RowsBean> mList, int itemLayoutId) {
            super(context, mList, itemLayoutId);
            this.context = context;
            this.mList = mList;
        }


        private void initphotodata(final int sn) {
            if(sn==0)
            {
                return;
            }
            RequestParams params = new RequestParams(AppInterfaceConfig.BASE_URL + "course/userTcPhoto/findTc/" + sn);
            x.http().get(params, new Callback.CommonCallback<String>() {
                @Override
                public void onSuccess(String result) {
                    SpecifiedPhotoBean specifiedPhotoBean = JSON.parseObject(result, SpecifiedPhotoBean.class);
                    List<SpecifiedPhotoBean.RowsBean> rows = specifiedPhotoBean.getRows();
                    if (rows.size() == 0) {
                        SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("photourl" + sn, "");
                        edit.commit();
                        return;
                    }
                    if(rows.size()==1) {
                        String url = specifiedPhotoBean.getRows().get(0).getUrl();
                        if (url == null) {
                            SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp.edit();
                            edit.putString("photourl" + sn, "");
                            edit.commit();

                        } else {
                            SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp.edit();
                            edit.putString("photourl" + sn, url);
                            edit.commit();
                        }
                    }else if(rows.size()==2)
                    {
                        String url = specifiedPhotoBean.getRows().get(0).getUrl();
                        String url1 = specifiedPhotoBean.getRows().get(1).getUrl();
                        if(url == null)
                        {
                            SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp.edit();
                            edit.putString("photourl" + sn, "");
                            edit.commit();
                        }else
                        {
                            SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp.edit();
                            edit.putString("photourl" + sn, url);
                            edit.commit();
                            if(url1==null)
                            {
                                SharedPreferences sp1 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit1 = sp1.edit();
                                edit1.putString("photourl1" + sn, "");
                                edit1.commit();
                            }else {
                                SharedPreferences sp1 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit1 = sp1.edit();
                                edit1.putString("photourl1" + sn, url1);
                                edit1.commit();
                            }
                        }

                    }else if(rows.size()==3)
                    {
                        String url = specifiedPhotoBean.getRows().get(0).getUrl();
                        String url1 = specifiedPhotoBean.getRows().get(1).getUrl();
                        String url2 = specifiedPhotoBean.getRows().get(2).getUrl();
                        if(url == null)
                        {
                            SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp.edit();
                            edit.putString("photourl" + sn, "");
                            edit.commit();
                        }else
                        {
                            SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp.edit();
                            edit.putString("photourl" + sn, url);
                            edit.commit();
                            if(url1==null)
                            {
                                SharedPreferences sp1 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit1 = sp1.edit();
                                edit1.putString("photourl1" + sn, "");
                                edit1.commit();
                            }else {
                                SharedPreferences sp1 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit1 = sp1.edit();
                                edit1.putString("photourl1" + sn, url1);
                                edit1.commit();
                                if(url2==null)
                                {
                                    SharedPreferences sp2 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit2 = sp2.edit();
                                    edit2.putString("photourl2" + sn, "");
                                    edit2.commit();
                                }else{
                                    SharedPreferences sp2 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit2 = sp2.edit();
                                    edit2.putString("photourl2" + sn, url2);
                                    edit2.commit();
                                }

                            }
                        }

                    }else if(rows.size()==4)
                    {
                        String url = specifiedPhotoBean.getRows().get(0).getUrl();
                        String url1 = specifiedPhotoBean.getRows().get(1).getUrl();
                        String url2 = specifiedPhotoBean.getRows().get(2).getUrl();
                        String url3 = specifiedPhotoBean.getRows().get(3).getUrl();
                        if(url == null)
                        {
                            SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp.edit();
                            edit.putString("photourl" + sn, "");
                            edit.commit();
                        }else
                        {
                            SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp.edit();
                            edit.putString("photourl" + sn, url);
                            edit.commit();
                            if(url1==null)
                            {
                                SharedPreferences sp1 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit1 = sp1.edit();
                                edit1.putString("photourl1" + sn, "");
                                edit1.commit();
                            }else {
                                SharedPreferences sp1 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit1 = sp1.edit();
                                edit1.putString("photourl1" + sn, url1);
                                edit1.commit();
                                if(url2==null)
                                {
                                    SharedPreferences sp2 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit2 = sp2.edit();
                                    edit2.putString("photourl2" + sn, "");
                                    edit2.commit();
                                }else{
                                    SharedPreferences sp2 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit2 = sp2.edit();
                                    edit2.putString("photourl2" + sn, url2);
                                    edit2.commit();

                                    if(url3==null)
                                    {
                                        SharedPreferences sp3 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit3 = sp3.edit();
                                        edit3.putString("photourl3" + sn, "");
                                        edit3.commit();
                                    }else {
                                        SharedPreferences sp3 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit3 = sp3.edit();
                                        edit3.putString("photourl3" + sn, url3);
                                        edit3.commit();;
                                    }


                                }

                            }
                        }

                    }else if(rows.size()>=5)
                    {
                        String url = specifiedPhotoBean.getRows().get(0).getUrl();
                        String url1 = specifiedPhotoBean.getRows().get(1).getUrl();
                        String url2 = specifiedPhotoBean.getRows().get(2).getUrl();
                        String url3 = specifiedPhotoBean.getRows().get(3).getUrl();
                        String url4 = specifiedPhotoBean.getRows().get(4).getUrl();
                        if(url == null)
                        {
                            SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp.edit();
                            edit.putString("photourl" + sn, "");
                            edit.commit();
                        }else
                        {
                            SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp.edit();
                            edit.putString("photourl" + sn, url);
                            edit.commit();
                            if(url1==null)
                            {
                                SharedPreferences sp1 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit1 = sp1.edit();
                                edit1.putString("photourl1" + sn, "");
                                edit1.commit();
                            }else {
                                SharedPreferences sp1 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit1 = sp1.edit();
                                edit1.putString("photourl1" + sn, url1);
                                edit1.commit();
                                if(url2==null)
                                {
                                    SharedPreferences sp2 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit2 = sp2.edit();
                                    edit2.putString("photourl2" + sn, "");
                                    edit2.commit();
                                }else{
                                    SharedPreferences sp2 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit2 = sp2.edit();
                                    edit2.putString("photourl2" + sn, url2);
                                    edit2.commit();

                                    if(url3==null)
                                    {
                                        SharedPreferences sp3 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit3 = sp3.edit();
                                        edit3.putString("photourl3" + sn, "");
                                        edit3.commit();
                                    }else {
                                        SharedPreferences sp3 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit3 = sp3.edit();
                                        edit3.putString("photourl3" + sn, url3);
                                        edit3.commit();;
                                        if(url4==null)
                                        {
                                            SharedPreferences sp4 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                                    Context.MODE_PRIVATE);
                                            SharedPreferences.Editor edit4 = sp4.edit();
                                            edit4.putString("photourl4" + sn, "");
                                            edit4.commit();
                                        }else {
                                            SharedPreferences sp4 = getSharedPreferences("SpecifiedLearningBusinessActivity",
                                                    Context.MODE_PRIVATE);
                                            SharedPreferences.Editor edit4 = sp4.edit();
                                            edit4.putString("photourl4" + sn, url4);
                                            edit4.commit();
                                        }
                                    }
                                }
                            }
                        }

                    }
                }

                @Override
                public void onError(Throwable ex, boolean isOnCallback) {
                    showToast("网络连接错误");
                }

                @Override
                public void onCancelled(CancelledException cex) {

                }

                @Override
                public void onFinished() {

                }
            });


        }


        @Override
        public void convert(ViewHolder holder, final SpecifiedLearningCourseBean.RowsBean item, final int positon) {

            TextView tv_ttName = holder.getView(R.id.tv_ttName);
            TextView tv_courseLength = holder.getView(R.id.tv_courseLength);
            TextView tv_creationDate = holder.getView(R.id.tv_creationDate);
            TextView tv_courseName = holder.getView(R.id.tv_courseName);
            TextView tv_learnyesorno = holder.getView(R.id.tv_parent4);
            TextView tv_buxue = holder.getView(R.id.tv_parent8);
            //  TextView tv_supermarket = holder.getView(R.id.tv_parent5);
            TextView tv_learnphoto = holder.getView(R.id.tv_learnphoto);//学习照片
            final TextView tv_learn = holder.getView(R.id.tv_learn);

            //     int otcSn = mList.get(positon).getOtcSn();
            long creationDate = mList.get(positon).getCreationDate();
            int mark = mList.get(positon).getMark();
            int muMark = mList.get(positon).getMuMark();
            String ttName = mList.get(positon).getTtName();
            String courseName = mList.get(positon).getCourseName();
            int courseLength = mList.get(positon).getCourseLength();
            int readLength = mList.get(positon).getReadLength();
            final int sn = mList.get(positon).getSn();
            if(sn==0)
            {
                initphotodata(0);
            }else{
                initphotodata(sn);
            }

            if (ttName == null) {
                tv_ttName.setText("");
            } else {
                tv_ttName.setText(ttName);
            }
            if (courseName == null) {
                tv_courseName.setText("");
            } else {
                tv_courseName.setText(courseName);
            }
            if (courseLength == 0) {
                tv_courseLength.setText("分钟");
            } else {
                tv_courseLength.setText(courseLength + "分钟");
            }

                if (mark == 1) {
                    tv_learnyesorno.setVisibility(View.VISIBLE);
                    tv_learnyesorno.setText("已学习");
                    tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_yes);
                    tv_learn.setVisibility(View.INVISIBLE);
                    tv_learnphoto.setVisibility(View.VISIBLE);

                } else if (mark == 0) {
                    if (readLength > 0) {
                        tv_learnyesorno.setVisibility(View.VISIBLE);
                        tv_learnyesorno.setText("未学完");
                        tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_noorange);
                        tv_learn.setVisibility(View.VISIBLE);
                        tv_learn.setText("继续学习");
                        tv_learnphoto.setVisibility(View.VISIBLE);
                    } else {
                        tv_learnyesorno.setVisibility(View.VISIBLE);
                        tv_learnyesorno.setText("未学习");
                        tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_nored);
                        tv_learn.setVisibility(View.VISIBLE);
                        tv_learn.setText("开始学习");
                        tv_learnphoto.setVisibility(View.GONE);
                    }
                }

            if (muMark == 1) {
                tv_buxue.setVisibility(View.VISIBLE);

            } else {
                tv_buxue.setVisibility(View.GONE);
            }

            tv_learnphoto.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Utils.isFastClicker()) {
                        return;
                    }
                    SharedPreferences sp = getSharedPreferences("SpecifiedLearningBusinessActivity",
                            Context.MODE_PRIVATE);
                    String photourl = sp.getString("photourl" + sn, "");
                    String photourl1 = sp.getString("photourl1" + sn, "");
                    String photourl2 = sp.getString("photourl2" + sn, "");
                    String photourl3 = sp.getString("photourl3" + sn, "");
                    String photourl4 = sp.getString("photourl4" + sn, "");
                    if (photourl.equals("")) {
                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SpecifiedLearningBusinessActivity.this);
                        builder1.setMessage("您在本课程没有学习照片。");
                        builder1.setTitle("提示:");
                        builder1.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                ;
                                //设置你的操作事项
                            }
                        });
                        builder1.create().show();
                    } else {
                        View contentView = LayoutInflater.from(SpecifiedLearningBusinessActivity.this).inflate(R.layout.popwindow_showphoto_layout, null);
                        mPopWindow = new PopupWindow(contentView,
                                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
                        mPopWindow.showAtLocation(tv_title, Gravity.CENTER, 0, 0);
                        TextView tv_dismiss = (TextView) contentView.findViewById(R.id.tv_dismiss);
                        tv_dismiss.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mPopWindow.dismiss();
                            }
                        });
                        final ImageView img_photo1 = (ImageView) contentView.findViewById(R.id.img_photo1);
                        final ImageView img_photo2 = (ImageView) contentView.findViewById(R.id.img_photo2);
                        final ImageView img_photo3 = (ImageView) contentView.findViewById(R.id.img_photo3);
                        final ImageView img_photo4 = (ImageView) contentView.findViewById(R.id.img_photo4);
                        final ImageView img_photo5 = (ImageView) contentView.findViewById(R.id.img_photo5);
                        if (photourl.contains("aliyuncs.com")) {
                            Picasso.with(context).load(Uri.parse(photourl)).placeholder(R.mipmap.no_data).into(img_photo1);
                        } else {

                            Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl))).placeholder(R.mipmap.no_data).into(img_photo1);
                        }
                        if(!photourl1.equals(""))
                        {
                            if (photourl1.contains("aliyuncs.com")) {
                                Picasso.with(context).load(Uri.parse(photourl1)).placeholder(R.mipmap.no_data).into(img_photo2);
                            } else {

                                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl1))).placeholder(R.mipmap.no_data).into(img_photo2);
                            }
                        }else{
                            img_photo2.setImageResource(R.drawable.normalphoto);
                        }
                        if(!photourl2.equals(""))
                        {
                            if (photourl2.contains("aliyuncs.com")) {
                                Picasso.with(context).load(Uri.parse(photourl2)).placeholder(R.mipmap.no_data).into(img_photo3);
                            } else {

                                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl2))).placeholder(R.mipmap.no_data).into(img_photo3);
                            }
                        }else{
                            img_photo3.setImageResource(R.drawable.normalphoto);
                        }
                        if(!photourl3.equals(""))
                        {
                            if (photourl3.contains("aliyuncs.com")) {
                                Picasso.with(context).load(Uri.parse(photourl3)).placeholder(R.mipmap.no_data).into(img_photo4);
                            } else {

                                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl3))).placeholder(R.mipmap.no_data).into(img_photo4);
                            }
                        }else{
                            img_photo4.setImageResource(R.drawable.normalphoto);
                        }
                        if(!photourl4.equals(""))
                        {
                            if (photourl4.contains("aliyuncs.com")) {
                                Picasso.with(context).load(Uri.parse(photourl4)).placeholder(R.mipmap.no_data).into(img_photo5);
                            } else {

                                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl4))).placeholder(R.mipmap.no_data).into(img_photo5);
                            }
                        }else{
                            img_photo5.setImageResource(R.drawable.normalphoto);
                        }
                    }
                }
            });
            if (creationDate > 0) {
                String begin = "";
                try {
                    //yyyy表示年MM表示月dd表示日
                    //yyyy-MM-dd是日期的格式，比如2015-12-12如果你要得到2015年12月12日就换成yyyy年MM月dd日
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
                    //进行格式化
                    begin = sdf.format(creationDate);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                tv_creationDate.setVisibility(View.VISIBLE);
                tv_creationDate.setText("学习时间: " + begin);

            } else {
                tv_creationDate.setVisibility(View.GONE);
            }

        }


    }
 }
